package edu.gdkm.sql.dao;

import edu.gdkm.sql.pojo.Userinfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserinfoMapper {

    // 查询全部用户信息
    @Select("SELECT * FROM userinfo")

    List<Userinfo> findAll();

    // 根据id查询用户信息
    @Select("SELECT * FROM userinfo WHERE id = #{id}")

    Userinfo findById(int id);

    // 根据用户名查询用户信息
    @Select("SELECT * FROM userinfo WHERE username = #{username}")

    Userinfo findByUsername(String username);

    // 插入用户信息
    @Insert("INSERT INTO userinfo(username, password, name, address, phone) VALUES(#{username}, #{password}, #{name}, #{address}, #{phone})")


    int insertUserinfo(Userinfo userinfo);

    // 更新用户信息
    @Update("UPDATE userinfo SET username=#{username}, password=#{password}, name=#{name}, address=#{address}, phone=#{phone} WHERE id=#{id}")

    int updateUserinfoById(Userinfo userinfo);

    // 删除用户信息
    @Delete("DELETE FROM userinfo WHERE id=#{id}")

    int deleteUserinfoById(int id);
}